package ui.panel.setup.subsidiary;

import cerebrum.common.ConfigPropertiesUtil;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Paint;
import javafx.scene.text.Font;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import ui.factory.SingletonFactory;
import ui.panel.setup.WallpaperTypeChoiceStage;
import ui.util.XBorder;

/**
 * 视频壁纸 ->选择屏保
 */
public class ScreenSaverSetUpStage {
    private Logger log = LoggerFactory.getLogger(ScreenSaverSetUpStage.class);
    private static ScreenSaverSetUpStage instance = null;
    private Pane root = new Pane();

    //调用单例工厂
    public static ScreenSaverSetUpStage getInstance() {
        if (instance == null) {
            instance = SingletonFactory.getWeakInstace(ScreenSaverSetUpStage.class);
        }
        return instance;
    }

    public Pane getPane() {
        Label tips = new Label();
        tips.setText("》 》》 》》 》 》 哈哈，骗你的，还需屏保设置");
        tips.setLayoutY(10);
        tips.setLayoutX(15);
        tips.setTextFill(Paint.valueOf("#54a5ff"));
        tips.setFont(new Font("宋体", 14));

        Button videoButton = new Button("视 频 屏 保");
        videoButton.setStyle("-fx-shape: 'M2285.743632 920.887865L17.908728 935.551953 339.001687 22.333237l2186.128966-9.607506-239.387021 908.162134z'; -fx-background-color:#00FFFF;");
        videoButton.setPrefHeight(40);
        videoButton.setPrefWidth(140);
        videoButton.setLayoutX(120);
        videoButton.setLayoutY(80);
        videoButton.setTextFill(Paint.valueOf("#F0FFFF"));

        Button pictureButton = new Button("美 图 屏 保");
        pictureButton.setStyle("-fx-shape: 'M2285.743632 920.887865L17.908728 935.551953 339.001687 22.333237l2186.128966-9.607506-239.387021 908.162134z'; -fx-effect: dropshadow(three-pass-box,rgba(255,255,255,0.66),10,0,0,0);-fx-background-color:#00FFFF; ");
        pictureButton.setPrefHeight(40);
        pictureButton.setPrefWidth(140);
        pictureButton.setLayoutX(300);
        pictureButton.setLayoutY(80);
        pictureButton.setTextFill(Paint.valueOf("#E0FFFF"));


        Button colseButton = new Button("关 闭 屏 保");
        colseButton.setStyle("-fx-shape: 'M2466.900818 994.423036L17.973694 1010.258087 291.901884 24.116601l2433.5016-10.374688-258.502666 980.681123z';-fx-effect: dropshadow(three-pass-box,rgba(255,255,255,0.66),10,0,0,0);-fx-background-color:#00FFFF;");
        colseButton.setPrefHeight(40);
        colseButton.setPrefWidth(140);
        colseButton.setLayoutX(480);
        colseButton.setLayoutY(80);
        colseButton.setTextFill(Paint.valueOf("#F5F5F5"));


        videoButton.setOnMouseEntered(event -> {
            videoButton.setBorder(new XBorder("#F0F8FF").build());
        });
        videoButton.setOnMouseExited(event -> {
            videoButton.setBorder(null);
        });
        videoButton.setOnMouseClicked(event -> {
            saveConfig("video");
            log.info("设置屏保：视频屏保");
            root.getChildren().removeAll(tips, videoButton, pictureButton,colseButton);
            Pane timePane = ScreenSaverTimeStage.getInstance().getRootPane();
            tips.setText("》 》》 》》 》 》 设置屏保唤醒时间");
            root.getChildren().addAll(tips,timePane);
            //TODO 通知屏保运行
        });


//------------------------- 按钮事件-----------------------
        pictureButton.setOnMouseEntered(event -> {
            pictureButton.setBorder(new XBorder("#F0F8FF").build());
        });
        pictureButton.setOnMouseExited(event -> {
            pictureButton.setBorder(null);
        });
        pictureButton.setOnMouseClicked(event -> {
            saveConfig("picture");
            log.info("设置屏保：美图屏保");
            //把此页面抬走
            WallpaperTypeChoiceStage.getInstance().removeSetUpMenu();
            //TODO 展示壁纸屏保设置界面
        });

        colseButton.setOnMouseEntered(event ->
                colseButton.setBorder(new XBorder("#F0F8FF").build()));

        colseButton.setOnMouseExited(event -> {
            colseButton.setBorder(null);
        });
        colseButton.setOnMouseClicked(event -> {
            saveConfig("close");
            log.info("设置关闭屏保！");
            //把此页面抬走
            WallpaperTypeChoiceStage.getInstance().removeSetUpMenu();
            //TODO 通知屏保运行

        });

        root.getChildren().addAll(tips, videoButton, pictureButton, colseButton);
        return root;
    }

    private void saveConfig(String str) {
        ConfigPropertiesUtil.set("ScreenSaver_Type", str);
    }
}
